#include "varietywidget.h"
#include "ui_varietywidget.h"

#include "word.h"

VarietyWidget::VarietyWidget(QWidget *parent)
    : QDockWidget(parent)
    , ui(new Ui::VarietyWidget)
{
    ui->setupUi(this);
    setWindowTitle("单词分类");

    SetVariety();

    connect(ui->pushButton_exit,&QPushButton::clicked,this,[=](){
        this->close();
        emit CloseWidget();
    });
}

VarietyWidget::~VarietyWidget()
{
    delete ui;
}

void VarietyWidget::closeEvent(QCloseEvent * event) {
    emit CloseWidget();
    event->accept();
}

void VarietyWidget::SetVariety() {
    QLabel *label[9] = {ui->label_1,ui->label_2,ui->label_3,ui->label_4,ui->label_5,ui->label_6,ui->label_7,ui->label_8,ui->label_9};
    QLineEdit *lineEdit[9] = {ui->lineEdit_1,ui->lineEdit_2,ui->lineEdit_3,ui->lineEdit_4,ui->lineEdit_5,ui->lineEdit_6,ui->lineEdit_7,ui->lineEdit_8,ui->lineEdit_9};
    for(int i = 0;i < 9;i++) {
        label[i]->setText(Word::IntToVarietyString_cn(i));
        lineEdit[i]->setText(Word::IntToVarietyString_en(i));

        lineEdit[i]->setReadOnly(true);

        if(Word::ReadOnly(Word::IntToVariety(i))) {
            lineEdit[i]->setReadOnly(true);
            lineEdit[i]->setStyleSheet("background-color: lightgrey;");
        }
    }
}
